package com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.assembler;

import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.DispatchMemoReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.entity.dispatch.DispatchMemo;
import com.jwds.digital.bios.business.core.infrastructure.vo.dispatch.DispatchMemoRespVO;

import java.util.Objects;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * DispatchMemo DTO与Entity之间的相互转换
 *
 * @author 林柏云
 * @date 2024-12-23
 */
public class DispatchMemoAssembler {

  /**
  * 将传输对象转换为实体对象
  *
  * @param dto 传输对象
  * @return 实体对象
  */
  public static DispatchMemo dto2entity(DispatchMemoReqDTO dto)  {
    if (dto == null) {
      return null;
    }
    DispatchMemo entity = new DispatchMemo();
    entity.setSupplierCode(dto.getSupplierCode());
    entity.setSupplierName(dto.getSupplierName());
    entity.setMemo(dto.getMemo());
    return entity;
  }

  /**
  * 将传输对象转换为实体对象
  *
  * @param dto 传输对象
  * @param entity 原实体对象
  * @return 实体对象
  */
  public static DispatchMemo dto2entity(DispatchMemoReqDTO dto, DispatchMemo entity){
    if (dto == null) {
      return null;
    }
    if(Objects.nonNull(dto.getSupplierCode())) {
      entity.setSupplierCode(dto.getSupplierCode());
    }
    if(Objects.nonNull(dto.getSupplierName())) {
      entity.setSupplierName(dto.getSupplierName());
    }
    if(Objects.nonNull(dto.getMemo())) {
      entity.setMemo(dto.getMemo());
    }
    return entity;
  }

  /**
  * 将实体对象转换为传输对象
  *
  * @param entity 实体对象
  * @return 传输对象
  */
  public static DispatchMemoRespVO entity2dto(DispatchMemo entity) {
    if (entity == null) {
      return null;
    }
    DispatchMemoRespVO dto = new DispatchMemoRespVO();
    dto.setId(entity.getId());
    dto.setSupplierCode(entity.getSupplierCode());
    dto.setSupplierName(entity.getSupplierName());
    dto.setMemo(entity.getMemo());
    dto.setCreateUser(entity.getCreateUser());
    dto.setCreateTime(entity.getCreateTime());
    dto.setModifyUser(entity.getModifyUser());
    dto.setModifyTime(entity.getModifyTime());
    return dto;
  }

}
